﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FantastPlatform.Framework;
using FantastPlatform.Framework.Core;
using FantastPlatform.Framework.Model;

namespace FantastPlatform.Decision.UI.Service
{
    public partial class MeetingService : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

         //   IMeetingService noticeService = ServiceFactory.CreateService<INoticeService>();

            ConditionGroup group = new ConditionGroup();
            int totalCount = 0;
            switch (Action)
            {
                case "Add":
                    string data = Data;
                   // INotice notice = (INotice)JsonToEntity<FantastPlatform.Community.Model.Notice>(RepairString(data));                   
                  
                    //if (notice.Id == 0)
                    //{ 
                    //    notice.Enable = true;
                    //    notice.CreatePolice = new Employee { Id = LoginEmployee.Id };
                    //    notice.CreateDate = DateTime.Now;
                    //    noticeService.Create(notice);
                    //    ReturnSuccessMessage("保存通知成功");
                    //}
                    //else
                    //{
                    //    INotice OldNotice = noticeService.Get(notice.Id);
                    //    notice.CreatePolice = OldNotice.CreatePolice;
                    //    notice.ModifyDate = DateTime.Now;
                    //    notice.CreateDate = OldNotice.CreateDate;
                    //    noticeService.Update(notice);
                    //    ReturnSuccessMessage("更新通知成功");
                    //}
                    break;
                case "Search":
                    //Condition enableCondition = new Condition() { Type = typeof(bool).FullName, Field = "Enable", Value1 = true };
                    //group.Conditions.Add(enableCondition);
                    //IList<Sort> sorts = new List<Sort>();
                    //sorts.Add(new Sort() { Field = "CreateDate", Order = Orders.Asc });
                    //IList<INotice> noticeList = noticeService.Search(group, sorts, PageSize, SelfPage, out totalCount);
                    //var obj = from n in noticeList
                    //          select new
                    //          {
                    //              Id = n.Id,
                    //              Name = n.Name,
                    //              Content = n.Content,
                    //              PoliceName = n.CreatePolice.Name,
                    //              CreateDate = n.CreateDate.ToString(),
                    //              Unit = n.CreatePolice.EmployeePosts[0].Post.Organization.Name,
                    //              PoliceCode = n.CreatePolice.Code
                    //          };
                    //ReturnList(totalCount, obj.ToList());
                    break;
                case "SearchByCondition":
                    //string Searchjson = RepairString(Data);
                    //notice = JsonToEntity<FantastPlatform.Community.Model.Notice>(Searchjson);
                    //enableCondition = new Condition() { Type = typeof(bool).FullName, Field = "Enable", Value1 = true };
                    //Condition condition1 = new Condition() { Type = typeof(string).FullName, Field = "Name", Value1 = '%' + notice.Name + '%', Comparison = Comparisons.Like, Relation = Relations.And };
                    //group.Conditions.Add(enableCondition);
                    //group.Conditions.Add(condition1);
                    //sorts = new List<Sort>();
                    //sorts.Add(new Sort() { Field = "CreateDate", Order = Orders.Asc });
                    //noticeList = noticeService.Search(group, sorts, PageSize, SelfPage, out totalCount);
                    // obj = from n in noticeList
                    //      select new
                    //      {
                    //          Id = n.Id,
                    //          Name = n.Name,
                    //          Content = n.Content,
                    //          PoliceName = n.CreatePolice.Name,
                    //          CreateDate = n.CreateDate.ToString(),
                    //          Unit = n.CreatePolice.EmployeePosts[0].Post.Organization.Name,                             
                    //          PoliceCode = n.CreatePolice.Code
                    //      };
                    //var objList = obj.ToList();
                    //ReturnList(objList.Count, objList);
                    break;
                case "Get":
                    //notice = noticeService.Get(Id);
                    //object objNotice = (new
                    //                 {
                    //                     CreatePoliceManNumber = notice.CreatePolice.Code,
                    //                     Name = notice.Name,
                    //                     Content = notice.Content
                    //                 });
                    //ReturnObj(objNotice);
                    break;
                case "Delete":
                    //if (string.IsNullOrEmpty(Data))
                    //{
                    //    throw new Exception("传入的通知ID为空");
                    //}
                    //List<int> idList = new List<int>();
                    //string[] idStrList = Data.Split(',');
                    //foreach (string id in idStrList)
                    //{
                    //    idList.Add(int.Parse(id));
                    //}
                    //noticeService.Delete(idList);
                    ReturnSuccessMessage("删除通知成功");
                    break;
            }
        }
    }
}